package edu.ynu.se.xiecheng.achitectureclass.device.enums;

public enum DeviceCategory {
    SOIL_MOISTURE("soil_moisture", "土壤含水率"),
    SOIL_TEMPERATURE("soil_temperature", "土壤温度"),
    SOIL_CONDUCTIVITY("soil_conductivity", "土壤电导率"),
    SOIL_PH("soil_ph", "土壤pH值"),
    SOIL_NITROGEN("soil_nitrogen", "土壤氮含量"),
    SOIL_PHOSPHORUS("soil_phosphorus", "土壤磷含量"),
    SOIL_POTASSIUM("soil_potassium", "土壤钾含量"),
    SOIL_CO2("soil_co2", "土壤二氧化碳"),
    AIR_TEMPERATURE("air_temperature", "空气温度"),
    AIR_HUMIDITY("air_humidity", "空气湿度"),
    RELATIVE_HUMIDITY("relative_humidity", "空气相对湿度"),
    LIGHT_INTENSITY("light_intensity", "光照强度"),
    CAMERA("camera", "摄像头");

    private final String value;
    private final String description;

    DeviceCategory(String value, String description) {
        this.value = value;
        this.description = description;
    }

    public String getValue() {
        return value;
    }

    public String getDescription() {
        return description;
    }

    public static DeviceCategory fromString(String text) {
        if (text == null) return null;
        String normalized = text.toLowerCase().trim();
        for (DeviceCategory category : DeviceCategory.values()) {
            if (category.value.equals(normalized) || 
                (category.description != null && category.description.equals(normalized)) ||
                category.name().toLowerCase().equals(normalized)) {
                return category;
            }
        }
        throw new IllegalArgumentException("未知的设备类型: " + text);
    }
} 